﻿var lastScroll;
var delay = 30;
var speed = 500;
var img_w = 700;
var img_h = 410;
function centerIt() {
  $("#overPage").css("width", $(window).width());
  $("#overPage").css("height", $(document).height());
  $("#floating").css("left", $(window).width() / 2 - img_w / 2);
  $("#floating").css("top", $(window).height() / 2 - img_h / 2 + $(document).scrollTop());
}
$(document).ready(function () {
  $("#overPage").css("opacity", 0.5);
  $("#overPage,#floating").show();
  centerIt();
});
$(window).scroll(function () {
  setTimeout(function () { ani(); }, delay);
  lastScroll = new Date().getTime();
});
$(window).resize(function () {
  centerIt();
});
function ani() {
  if ((new Date().getTime() - lastScroll) >= (delay - 20)) {
    $("#floating").animate({ top: ($(window).height() / 2 - img_h / 2 + $(document).scrollTop()) }, speed);
  }
}
function closeMe() {
  $("#overPage,#floating").hide();
}